/**
 * ES开发环境配置类
 */
@Configuration
@Conditional(MsgMqDevCondition.class)
public class ElasticSearchDevConfig {
 
    @Value("${es.url}")
    private String esPath;
 
    @Value("${es.port}")
    private String esPort;
 
    @Bean
    public RestHighLevelClient restHighLevelClient(){
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost(esPath,Integer.parseInt(esPort),"http")
                ).setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
                    @Override
                    public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
                        return requestConfigBuilder.setConnectTimeout(90000000)//25hours
                                .setSocketTimeout(90000000);
                    }
                }).setHttpClientConfigCallback((httpAsyncClientBuilder -> {
                    httpAsyncClientBuilder.disableAuthCaching();//禁用身份验证缓存
                    //显式设置keepAliveStrategy
                    httpAsyncClientBuilder.setKeepAliveStrategy((httpResponse,httpContext) -> TimeUnit.MINUTES.toMillis(3));
                    //显式开启tcp keepalive
                    httpAsyncClientBuilder.setDefaultIOReactorConfig(IOReactorConfig.custom().setSoKeepAlive(true).build());
                    return httpAsyncClientBuilder;
                }))
        );
        return client;
    }
 
}